set.seed(1234)
n <- 2000
gender <- rep(0:1, each = n/2)
y <- sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x1 <- sample(0:10, n, replace = TRUE) + gender * y
x2 <- x1 + sample(0:10, n, replace = TRUE) + gender * y
y <- y + (x1 > median(x1) & x2 > median(x2) & gender == 1) * sample(0:10, n, replace = TRUE) * 2
dat <- data.frame(y = y, x1 = x1, x2 = x2, gender = gender)Treatment vs. effect contrasts
regression
statistics
contrasts
Abstract
Here is a simple example to show the differences between treatment and effect contrasts.
Example dataset
Create a random dataset with criteria y, predictors x1, x2 and gender.
yandgenderare correlatedyandx1are correlated only if gender is 1yandx2are correlated only if gender is 1x1andx2are correlatedx1andx2have an interaction effect on y only if gender is 1
Descriptives
psych::corr.test(dat)Call:psych::corr.test(x = dat)
Correlation matrix
y x1 x2 gender
y 1.00 0.79 0.82 0.68
x1 0.79 1.00 0.95 0.74
x2 0.82 0.95 1.00 0.79
gender 0.68 0.74 0.79 1.00
Sample Size
[1] 2000
Probability values (Entries above the diagonal are adjusted for multiple tests.)
y x1 x2 gender
y 0 0 0 0
x1 0 0 0 0
x2 0 0 0 0
gender 0 0 0 0
To see confidence intervals of the correlations, print with the short=FALSE option
psych::describe(dat)| vars | n | mean | sd | median | trimmed | mad | min | max | range | skew | kurtosis | se | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| y | 1 | 2000 | 11.6735 | 9.829965 | 8.0 | 10.58375 | 7.4130 | 0 | 40 | 40 | 0.8543788 | -0.4209326 | 0.2198047 |
| x1 | 2 | 2000 | 10.0920 | 6.802549 | 9.0 | 9.67625 | 7.4130 | 0 | 30 | 30 | 0.5169160 | -0.5958746 | 0.1521096 |
| x2 | 3 | 2000 | 20.2970 | 12.883508 | 17.0 | 19.30562 | 13.3434 | 0 | 58 | 58 | 0.6054280 | -0.6904413 | 0.2880840 |
| gender | 4 | 2000 | 0.5000 | 0.500125 | 0.5 | 0.50000 | 0.7413 | 0 | 1 | 1 | 0.0000000 | -2.0009998 | 0.0111831 |
Contrasts
The left part of the table is with gender as treatment contrast (0 vs. 1) and the right part with gender as effect contrast (-1 vs. 1)
# Gender has values 0 vs. 1 (treatment contrast)
fit1 <- lm(y ~ gender * x1 * x2, data = dat)
# Gender hast -1 vs. 1 (effect contrast)
dat$gender <- car::recode(dat$gender, "0 = -1; 1 = 1")
fit2 <- lm(y ~ gender * x1 * x2, data = dat)
sjPlot::tab_model(fit1, fit2, show.se = TRUE, show.ci = FALSE, col.order = c("est", "se", "std.est", "p"), digits = 4, dv.labels = c("Treatment contrast<br> for gender", "Effect contrast<br> for gender"))| Treatment contrast for gender |
Effect contrast for gender |
|||||
| Predictors | Estimates | std. Error | p | Estimates | std. Error | p |
| (Intercept) | 5.2577 | 0.6189 | <0.001 | -4.6274 | 0.6427 | <0.001 |
| gender | -19.7703 | 1.2853 | <0.001 | -9.8852 | 0.6427 | <0.001 |
| x1 | -0.0695 | 0.1358 | 0.609 | 0.6640 | 0.0851 | <0.001 |
| x2 | -0.0270 | 0.0795 | 0.734 | 0.4363 | 0.0482 | <0.001 |
| gender × x1 | 1.4671 | 0.1702 | <0.001 | 0.7335 | 0.0851 | <0.001 |
| gender × x2 | 0.9267 | 0.0963 | <0.001 | 0.4633 | 0.0482 | <0.001 |
| x1 × x2 | 0.0056 | 0.0116 | 0.629 | -0.0124 | 0.0059 | 0.036 |
| (gender × x1) × x2 | -0.0360 | 0.0118 | 0.002 | -0.0180 | 0.0059 | 0.002 |
| Observations | 2000 | 2000 | ||||
| R2 / R2 adjusted | 0.738 / 0.737 | 0.738 / 0.737 | ||||
- The
interceptin model1 (treatment contrast) is the mean ofyfor gender 0 - The
interceptin model2 (effect contrast) is the mean ofyfor all data - All predictors in model1 without a
genderterm are effects for gender 0 while the interactions with agenderterm are effects for gender 1 - All predictors in model2 without a
genderterm are effects across gender while the interactions with agenderterm are the effects ofgender(subtracted for gender 0 and added for gender 1). genderhas a significant effect onyin both modelsx1,x2andx1*x2only have a significant effect onyin model 2- All
genderinteractions are significant in both models where the effect sizes and the standard errors of model2 are half of the corresponding values in model1, sopis identical.